<template>
  <div class="bottom-bar">
    <div class="check-content">
      <check-button
        class="check-button"
        :is-checked="isSelectAll"
        @click.native="checkClick"></check-button>
      <span>全选</span>
    </div>
    <div class="count">
      合计¥:{{totalPrice}}
    </div>
    <div class="calc">去计算:{{checkLength}}</div>
  </div>
</template>

<script>
  import CheckButton from "@/components/content/checkButton/CheckButton";
  import {mapGetters} from 'vuex'

  export default {
    name: "CartBottomBar",
    components: {
      CheckButton
    },
    data(){
      return{
        check: false
      }
    },
    computed: {
      ...mapGetters({
        cartList: 'getCartList',
        cartLength: 'cartListLength'
      }),
      totalPrice(){
        return this.cartList.filter(item=> item.isChecked)
          .reduce((previousValue,item) => previousValue + item.count * item.price,0)
      },
      checkLength(){
        return this.cartList.filter(item => item.isChecked)
          .reduce((previousValue,item)=> previousValue + item.count, 0)
      },
      isSelectAll(){
        if (this.cartLength === 0) {
          return false
        }else {
          return this.$store.state.CartProduct.isSelectAllBool
        }
      }
    },
    methods: {
      checkClick(){
        this.$store.commit('isSelectAll')
        // this.$toast.methods.isShow
      }
    },
  }
</script>

<style scoped>
  .bottom-bar{
    background-color: #dbe5ec;
    position: relative;
    display: flex;
    height: 40px;
    line-height: 40px;
  }
  .check-button{
    width: 20px;
    height: 20px;
    line-height: 20px;
    margin-right: 10px;
  }
  .check-content{
    display: flex;
    align-items: center;
    font-size: 13px;
    margin-left: 10px;
    width: 60px;
  }
  .count{
    color: #ff5777;
    padding-left: 50px;
    flex: 1;
    font-size: 13px;
  }
  .calc{
    width: 90px;
    color: white;
    text-align: center;
    background-color: #ff8198;
    font-size: 14px;
  }
</style>
